﻿using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MotionControl;
using WHW_NetUtility;
using System.Diagnostics;
using System.Threading;
using System.Windows.Forms;
using System.IO;
using HalconDotNet;
using Newtonsoft.Json;
using System.Text.RegularExpressions;
using XXTUserUI;
using System;

namespace MainFrame
{
    public partial class GlobalMotion
    {

        /// <summary>
        /// 流程-飞达取料
        /// </summary>
        public static void Task_Labeling()
        {
            try
            {
                string logFlow = e_LabelingFlow.ToString();
                var curPlate = e_platePro.双平台有;
                int camera1Time = 0;
                int camera2Time = 0;
                ///优先2平台
                var IsPlate2First = false;
                ///优先1平台
                var IsPlate1First = false;
                var getLabelTimes = 0;
                var getLabelTimes_auto = 0;
                var sw_fly = new Stopwatch();
                var sw_Scan = new Stopwatch();
                sw_fly.Restart();

                while (!GlobalVar.isExit)
                {
                    Thread.Sleep(8);
                    var nstop = -1;
                    if (!GlobalVar.isEstop)
                    {
                        if (GlobalVar.isAutoRun && !GlobalVar.IsManThrought)
                        {
                            if (GlobalVar.IsStart_EndWork)
                            {
                                e_LabelingFlow = e_Flow_Labeling.等待开始检测产品信号;
                                continue;
                            }
                            bool IshavePro3 = !GlobalMotion.Input_CardEx2[(int)e_input_extCard2.上输送产品检测3];//上输送产品检测3
                            bool IshavePro4 = !GlobalMotion.Input_CardEx2[(int)e_input_extCard2.上输送产品检测4];//上输送产品检测4
                            switch (e_LabelingFlow)
                            {
                                case e_Flow_Labeling.取标签:
                                    {
                                        var tempPlate = curPlate;
                                        if (IsPlate2First)
                                        {
                                            tempPlate = e_platePro.平台2;
                                        }
                                        if (IsPlate1First)
                                        {
                                            tempPlate = e_platePro.平台1;
                                        }
                                        getLabelTimes++;
                                        getLabelTimes_auto = 0;
                                        #region 只要一边没吸上标  就检测
                                        if (nLabelTimes == 0)
                                        {
                                            nLabelTimes++;

                                            var nairAll = Step_Labeling(e_Step_Label.检测吸标靶面真空, tempPlate);
                                            if (nairAll != (int)e_airResult.双平台已吸有料)
                                            {
                                                MutilStep(e_Mutil_step.等待飞达出标完成, tempPlate);
                                                #region 开始取标前  检测
                                                //   for (int m = 0; m < 1 + GlobalVar.userConfig.getFlyNGTimes; m++)
                                                for (int m = 0; m < 1; m++)
                                                {
                                                    if (tempPlate == e_platePro.平台1 && !Input_CardEx1[(int)e_input_extCard1.飞达1平台有料])
                                                    {
                                                        displalyInfo.displayInfoMain("飞达平台无料1触发飞达出标");
                                                        GlobalVar.isFlying1OK = false;
                                                        GlobalVar.IsflyStart1 = true;
                                                        MutilStep(e_Mutil_step.等待飞达出标完成, e_platePro.平台1);
                                                        Thread.Sleep(GlobalVar.motionConfig.flydelayCheck);
                                                        if (Input_CardEx1[(int)e_input_extCard1.飞达1平台有料])
                                                            break;
                                                    }
                                                    else if (tempPlate == e_platePro.平台2 && !Input_CardEx1[(int)e_input_extCard1.飞达2平台有料])
                                                    {
                                                        displalyInfo.displayInfoMain("飞达平台无料2触发飞达出标");
                                                        GlobalVar.isFlying2OK = false;
                                                        GlobalVar.IsflyStart2 = true;
                                                        MutilStep(e_Mutil_step.等待飞达出标完成, e_platePro.平台2);
                                                        Thread.Sleep(GlobalVar.motionConfig.flydelayCheck);
                                                        if (Input_CardEx1[(int)e_input_extCard1.飞达2平台有料])
                                                            break;
                                                    }
                                                    else if (tempPlate == e_platePro.双平台有)
                                                    {
                                                        if (!Input_CardEx1[(int)e_input_extCard1.飞达1平台有料] && !Input_CardEx1[(int)e_input_extCard1.飞达2平台有料])
                                                        {
                                                            displalyInfo.displayInfoMain("飞达平台无料1  飞达平台无料2  触发飞达出标");
                                                            GlobalVar.isFlying1OK = false;
                                                            GlobalVar.isFlying2OK = false;
                                                            GlobalVar.IsflyStart1 = true;
                                                            GlobalVar.IsflyStart2 = true;
                                                            MutilStep(e_Mutil_step.等待飞达出标完成, e_platePro.双平台有);
                                                            Thread.Sleep(GlobalVar.motionConfig.flydelayCheck);
                                                            if (Input_CardEx1[(int)e_input_extCard1.飞达1平台有料] && Input_CardEx1[(int)e_input_extCard1.飞达2平台有料])
                                                                break;
                                                        }
                                                        else if (!Input_CardEx1[(int)e_input_extCard1.飞达1平台有料])//平台1
                                                        {
                                                            displalyInfo.displayInfoMain("飞达平台无料1 触发飞达出标");
                                                            GlobalVar.isFlying1OK = false;
                                                            GlobalVar.IsflyStart1 = true;
                                                            MutilStep(e_Mutil_step.等待飞达出标完成, e_platePro.平台1);
                                                            Thread.Sleep(GlobalVar.motionConfig.flydelayCheck);
                                                            if (Input_CardEx1[(int)e_input_extCard1.飞达1平台有料])
                                                                break;
                                                        }
                                                        else if (!Input_CardEx1[(int)e_input_extCard1.飞达2平台有料])//平台2
                                                        {
                                                            displalyInfo.displayInfoMain("飞达平台无料2 触发飞达出标");
                                                            GlobalVar.isFlying2OK = false;
                                                            GlobalVar.IsflyStart2 = true;
                                                            MutilStep(e_Mutil_step.等待飞达出标完成, e_platePro.平台2);
                                                            Thread.Sleep(GlobalVar.motionConfig.flydelayCheck);
                                                            if (Input_CardEx1[(int)e_input_extCard1.飞达2平台有料])
                                                                break;
                                                        }
                                                    }
                                                }
                                                #endregion
                                            }
                                        }
                                        else
                                        {
                                            MutilStep(e_Mutil_step.等待飞达出标完成, tempPlate);
                                        }
                                        #endregion

                                        if (!GlobalVar.userConfig.IsGetLabelTwo || tempPlate != e_platePro.双平台有)
                                        {
                                            //吸标Ng 次数
                                            for (int nfly = 0; nfly < (2 + GlobalVar.userConfig.getLabelNGTimes); nfly++)
                                            {
                                                var curTempPlate = tempPlate;
                                                //平台2取料
                                                var nres = MutilStep(e_Mutil_step.移至取标位取标, curTempPlate);
                                                if (nres == -2 || nres == (int)e_airResult.平台2已吸有料 || nres == (int)e_airResult.平台1已吸有料 || nres == (int)e_airResult.双平台吸无料)//单双都失败/平台1失败/平台2失败
                                                {
                                                    if (nfly > GlobalVar.userConfig.getLabelNGTimes)
                                                    {
                                                        //GlobalVar.isPause = true;
                                                        if (1 == GlobalMotion.TipInfo($"飞达连续取标签吸真空异常,是否抛料?  是:继续   否抛料"))
                                                        {
                                                            e_LabelingFlow = e_Flow_Labeling.取标签;
                                                            GlobalVar.isPause = false;
                                                            nfly = 0;

                                                            if (!Input_CardEx1[(int)e_input_extCard1.飞达1平台有料])//平台1
                                                            {
                                                                GlobalVar.isFlying1OK = false;
                                                                GlobalVar.IsflyStart1 = true;
                                                                var resfly = MutilStep(e_Mutil_step.等待飞达出标完成, e_platePro.平台1);
                                                                if (resfly != 1)
                                                                    break;
                                                            }

                                                            if (!Input_CardEx1[(int)e_input_extCard1.飞达2平台有料])//平台2
                                                            {
                                                                GlobalVar.isFlying2OK = false;
                                                                GlobalVar.IsflyStart2 = true;
                                                                var resfly = MutilStep(e_Mutil_step.等待飞达出标完成, e_platePro.平台2);
                                                                if (resfly != 1)
                                                                    break;
                                                            }
                                                            continue;
                                                        }
                                                        else
                                                        {
                                                            GlobalVar.isPause = false;
                                                            if (getLabelTimes_auto < GlobalVar.userConfig.getLabelNGTimes_auto)
                                                            {
                                                                nfly = 0;
                                                                getLabelTimes_auto++;

                                                                var resOK1 = -1;                                                              
                                                                if (nres == (int)e_airResult.平台2已吸有料)
                                                                    resOK1 = MutilStep(e_Mutil_step.吸标NG取标流程, e_platePro.平台1);
                                                                else if (nres == (int)e_airResult.平台1已吸有料)
                                                                    resOK1 = MutilStep(e_Mutil_step.吸标NG取标流程, e_platePro.平台2);
                                                                else
                                                                    resOK1 = MutilStep(e_Mutil_step.吸标NG取标流程, e_platePro.双平台有);

                                                                if (resOK1 == 1 && !(IsNGlabelPos() != 1 || IsNGlabelOkExist() != 1))
                                                                {
                                                                    if (nres == (int)e_airResult.平台2已吸有料)//平台1
                                                                    {
                                                                        GlobalVar.isFlying1OK = false;
                                                                        GlobalVar.IsflyStart1 = true;
                                                                        var resfly = MutilStep(e_Mutil_step.等待飞达出标完成, e_platePro.平台1);
                                                                        if (resfly != 1)
                                                                            break;
                                                                    }
                                                                    else if (nres == (int)e_airResult.平台1已吸有料)//平台2
                                                                    {
                                                                        GlobalVar.isFlying2OK = false;
                                                                        GlobalVar.IsflyStart2 = true;
                                                                        var resfly = MutilStep(e_Mutil_step.等待飞达出标完成, e_platePro.平台2);
                                                                        if (resfly != 1)
                                                                            break;
                                                                    }
                                                                    else
                                                                    {
                                                                        GlobalVar.isFlying1OK = false;
                                                                        GlobalVar.isFlying2OK = false;
                                                                        GlobalVar.IsflyStart1 = true;
                                                                        GlobalVar.IsflyStart2 = true;
                                                                        var resfly = MutilStep(e_Mutil_step.等待飞达出标完成, e_platePro.双平台有);
                                                                        if (resfly != 1)
                                                                            break;
                                                                    }
                                                                   
                                                                    continue;
                                                                }
                                                                else
                                                                {
                                                                    //MachineState(e_MachineStatus.异常急停, $"双平台有{e_LabelingFlow.ToString()}:吸标NG放标处理");
                                                                    GlobalMotion.TipInfo($"双平台有{e_LabelingFlow.ToString()}:吸标NG放标处理");
                                                                    e_LabelingFlow = e_Flow_Labeling.到拍照位拍照;
                                                                    break;
                                                                }
                                                            }
                                                            else
                                                            {
                                                                //报警提示，不停机
                                                                if (GlobalMotion.TipInfo($"飞达连续取标签吸真空异常,请检查！是:继续   否急停") != 1)
                                                                {
                                                                    MachineState(e_MachineStatus.异常急停, $"双平台{e_LabelingFlow.ToString()}:吸标签吸真空");
                                                                }
                                                                else
                                                                {
                                                                    e_LabelingFlow = e_Flow_Labeling.取标签;
                                                                    nfly = 0;
                                                                    if (!Input_CardEx1[(int)e_input_extCard1.飞达1平台有料])//平台1
                                                                    {
                                                                        GlobalVar.isFlying1OK = false;
                                                                        GlobalVar.IsflyStart1 = true;
                                                                        var resfly = MutilStep(e_Mutil_step.等待飞达出标完成, e_platePro.平台1);
                                                                        if (resfly != 1)
                                                                            break;
                                                                    }

                                                                    if (!Input_CardEx1[(int)e_input_extCard1.飞达2平台有料])//平台2
                                                                    {
                                                                        GlobalVar.isFlying2OK = false;
                                                                        GlobalVar.IsflyStart2 = true;
                                                                        var resfly = MutilStep(e_Mutil_step.等待飞达出标完成, e_platePro.平台2);
                                                                        if (resfly != 1)
                                                                            break;
                                                                    }
                                                                    continue;
                                                                }
                                                                break;
                                                            }
                                                        }

                                                    }
                                                }
                                                else if (nres == -1)
                                                {
                                                    if (GlobalMotion.TipInfo($"移至取标位取标失败  是:继续   否急停") == 1)
                                                    {
                                                        e_LabelingFlow = e_Flow_Labeling.取标签;
                                                        nfly = 0;
                                                        if (!Input_CardEx1[(int)e_input_extCard1.飞达1平台有料])//平台1
                                                        {
                                                            GlobalVar.isFlying1OK = false;
                                                            GlobalVar.IsflyStart1 = true;
                                                            var resfly = MutilStep(e_Mutil_step.等待飞达出标完成, e_platePro.平台1);
                                                            if (resfly != 1)
                                                                break;
                                                        }

                                                        if (!Input_CardEx1[(int)e_input_extCard1.飞达2平台有料])//平台2
                                                        {
                                                            GlobalVar.isFlying2OK = false;
                                                            GlobalVar.IsflyStart2 = true;
                                                            var resfly = MutilStep(e_Mutil_step.等待飞达出标完成, e_platePro.平台2);
                                                            if (resfly != 1)
                                                                break;
                                                        }
                                                        continue;
                                                    }
                                                    else
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"双平台{e_LabelingFlow.ToString()}:移至取标位取标");
                                                        break;
                                                    }
                                                }
                                                else
                                                    break;
                                            }
                                            e_LabelingFlow = e_Flow_Labeling.到拍照位拍照;
                                        }
                                        else
                                        {
                                            for (int nfly = 0; nfly < (2 + GlobalVar.userConfig.getLabelNGTimes); nfly++)
                                            {
                                                var nres = MutilStep(e_Mutil_step.移至取标位取标, e_platePro.平台1);
                                                if (nres == -2)//吸标失败
                                                {
                                                    if (!Input_CardEx1[(int)e_input_extCard1.飞达1平台有料] && false)//只出一次标
                                                    {
                                                        nfly = 0;
                                                    }
                                                    else
                                                    {
                                                        if (nfly >= GlobalVar.userConfig.getLabelNGTimes)
                                                        {
                                                            if (1 == GlobalMotion.TipInfo($"平台1飞达连续取标签吸真空异常?  是:继续   否抛料"))
                                                            {
                                                                e_LabelingFlow = e_Flow_Labeling.取标签;
                                                                nfly = 0;
                                                                GlobalVar.isFlying1OK = false;
                                                                GlobalVar.IsflyStart1 = true;
                                                                var resfly = MutilStep(e_Mutil_step.等待飞达出标完成, e_platePro.平台1);
                                                                if (resfly != 1)
                                                                    break;
                                                                continue;
                                                            }
                                                            else
                                                            {
                                                                if (getLabelTimes_auto < GlobalVar.userConfig.getLabelNGTimes_auto)
                                                                {
                                                                    getLabelTimes_auto++;
                                                                    var resOK1 = MutilStep(e_Mutil_step.吸标NG取标流程, e_platePro.平台1);

                                                                    if (resOK1 == 1 && !(IsNGlabelPos() != 1 || IsNGlabelOkExist() != 1))
                                                                    {
                                                                        if (!Input_CardEx1[(int)e_input_extCard1.飞达1平台有料])//平台1
                                                                        {
                                                                            GlobalVar.isFlying1OK = false;
                                                                            GlobalVar.IsflyStart1 = true;
                                                                            var resfly = MutilStep(e_Mutil_step.等待飞达出标完成, e_platePro.平台1);
                                                                            if (resfly != 1)
                                                                                break;
                                                                        }
                                                                        nfly = 0;
                                                                        continue;
                                                                    }
                                                                    else
                                                                    {
                                                                        MachineState(e_MachineStatus.异常急停, $"平台1{e_LabelingFlow.ToString()}:吸标NG放标处理");
                                                                        break;
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    //报警提示，不停机
                                                                    if (GlobalMotion.TipInfo($"飞达连续取标签吸真空异常,请检查！是:继续   否急停") != 1)
                                                                    {
                                                                        MachineState(e_MachineStatus.异常急停, $"双平台{e_LabelingFlow.ToString()}:吸标签吸真空");
                                                                    }
                                                                    else
                                                                    {
                                                                        e_LabelingFlow = e_Flow_Labeling.取标签;
                                                                        nfly = 0;
                                                                        if (!Input_CardEx1[(int)e_input_extCard1.飞达1平台有料])//平台1
                                                                        {
                                                                            GlobalVar.isFlying1OK = false;
                                                                            GlobalVar.IsflyStart1 = true;
                                                                            var resfly = MutilStep(e_Mutil_step.等待飞达出标完成, e_platePro.平台1);
                                                                            if (resfly != 1)
                                                                                break;
                                                                        }
                                                                        continue;
                                                                    }
                                                                    break;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                else if (nres == -1)
                                                {
                                                    if (GlobalMotion.TipInfo($"移至取标位取标失败  是:继续   否急停") == 1)
                                                    {
                                                        e_LabelingFlow = e_Flow_Labeling.取标签;
                                                        nfly = 0;
                                                        if (!Input_CardEx1[(int)e_input_extCard1.飞达1平台有料])//平台1
                                                        {
                                                            GlobalVar.isFlying1OK = false;
                                                            GlobalVar.IsflyStart1 = true;
                                                            var resfly = MutilStep(e_Mutil_step.等待飞达出标完成, e_platePro.平台1);
                                                            if (resfly != 1)
                                                                break;
                                                        }

                                                        continue;
                                                    }
                                                    else
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"双平台{e_LabelingFlow.ToString()}:移至取标位取标");
                                                        break;
                                                    }
                                                }
                                                else
                                                    break;
                                            }

                                            for (int nfly = 0; nfly < (2 + GlobalVar.userConfig.getLabelNGTimes); nfly++)
                                            {
                                                var nres = MutilStep(e_Mutil_step.移至取标位取标, e_platePro.平台2);
                                                if (nres == -2)//单都失败
                                                {
                                                    if (!Input_CardEx1[(int)e_input_extCard1.飞达2平台有料] && false)//只出一次标  防止叠标
                                                    {
                                                        nfly = 0;
                                                    }
                                                    else
                                                    {
                                                        if (1 == GlobalMotion.TipInfo($"平台2飞达连续取标签吸真空异常?  是:继续   否抛料"))
                                                        {
                                                            e_LabelingFlow = e_Flow_Labeling.取标签;
                                                            nfly = 0;
                                                            if (!Input_CardEx1[(int)e_input_extCard1.飞达2平台有料])//平台1
                                                            {
                                                                GlobalVar.isFlying2OK = false;
                                                                GlobalVar.IsflyStart2 = true;
                                                                var resfly = MutilStep(e_Mutil_step.等待飞达出标完成, e_platePro.平台2);
                                                                if (resfly != 1)
                                                                    break;
                                                            }

                                                            continue;
                                                        }
                                                        else
                                                        {
                                                            if (nfly >= GlobalVar.userConfig.getLabelNGTimes)
                                                            {
                                                                if (getLabelTimes_auto < GlobalVar.userConfig.getLabelNGTimes_auto)
                                                                {
                                                                    getLabelTimes_auto++;
                                                                    var resOK1 = MutilStep(e_Mutil_step.吸标NG取标流程, e_platePro.平台2);
                                                                    if (resOK1 == 1 && !(IsNGlabelPos() != 1 || IsNGlabelOkExist() != 1))
                                                                    {
                                                                        nfly = 0;
                                                                        if (!Input_CardEx1[(int)e_input_extCard1.飞达2平台有料])//平台2
                                                                        {
                                                                            GlobalVar.isFlying2OK = false;
                                                                            GlobalVar.IsflyStart2 = true;
                                                                        }
                                                                        var resfly = MutilStep(e_Mutil_step.等待飞达出标完成, e_platePro.平台2);
                                                                        if (resfly != 1)
                                                                            break;
                                                                        continue;
                                                                    }
                                                                    else
                                                                    {
                                                                        MachineState(e_MachineStatus.异常急停, $"平台2{e_LabelingFlow.ToString()}:吸标NG放标处理");
                                                                        break;
                                                                    }

                                                                }
                                                                else
                                                                {
                                                                    //报警提示，不停机
                                                                    if (GlobalMotion.TipInfo($"飞达连续取标签吸真空异常,请检查！是:继续   否急停") != 1)
                                                                    {
                                                                        MachineState(e_MachineStatus.异常急停, $"双平台{e_LabelingFlow.ToString()}:吸标签吸真空");
                                                                    }
                                                                    else
                                                                    {
                                                                        e_LabelingFlow = e_Flow_Labeling.取标签;
                                                                        nfly = 0;
                                                                        if (!Input_CardEx1[(int)e_input_extCard1.飞达2平台有料])//平台1
                                                                        {
                                                                            GlobalVar.isFlying2OK = false;
                                                                            GlobalVar.IsflyStart2 = true;
                                                                            var resfly = MutilStep(e_Mutil_step.等待飞达出标完成, e_platePro.平台2);
                                                                            if (resfly != 1)
                                                                                break;
                                                                        }
                                                                        continue;
                                                                    }
                                                                    break;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                else if (nres == -1)
                                                {
                                                    if (GlobalMotion.TipInfo($"移至取标位取标失败  是:继续   否急停") == 1)
                                                    {
                                                        e_LabelingFlow = e_Flow_Labeling.取标签;
                                                        nfly = 0;
                                                        if (!Input_CardEx1[(int)e_input_extCard1.飞达2平台有料])//平台1
                                                        {
                                                            GlobalVar.isFlying2OK = false;
                                                            GlobalVar.IsflyStart2 = true;
                                                            var resfly = MutilStep(e_Mutil_step.等待飞达出标完成, e_platePro.平台2);
                                                            if (resfly != 1)
                                                                break;
                                                        }
                                                        continue;
                                                    }
                                                    else
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"双平台{e_LabelingFlow.ToString()}:移至取标位取标");
                                                        break;
                                                    }
                                                }
                                                else
                                                    break;
                                            }
                                            e_LabelingFlow = e_Flow_Labeling.到拍照位拍照;
                                        }
                                        
                                    }
                                    break;
                                case e_Flow_Labeling.到拍照位拍照:
                                    {
                                        var nres = -1;
                                        var tempPlate = curPlate;
                                        if (IsPlate2First)
                                        {
                                            IsPlate2First = false;
                                            tempPlate = e_platePro.平台2;
                                        }
                                        if (IsPlate1First)
                                        {
                                            IsPlate1First = false;
                                            tempPlate = e_platePro.平台1;
                                        }
                                        if (tempPlate == e_platePro.双平台有)
                                        {
                                            camera1Time++;
                                            camera2Time++;

                                            //nres = Step_Labeling(e_Step_Label.移至拍照位, tempPlate);
                                            //if (nres != 1)
                                            //{
                                            //    MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:移至拍照位");
                                            //    continue;
                                            //}
                                            //nres = Step_Labeling(e_Step_Label.拍照, tempPlate);
                                            //if (nres != 1)
                                            //{
                                            //    MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:拍照");
                                            //    continue;
                                            //}

                                            //左工位移到下相机上方并拍照1
                                            nres = Step_Labeling(e_Step_Label.移至拍照安全位X, e_platePro.平台2);
                                            if (nres != 1)
                                            {
                                                MachineState(e_MachineStatus.异常急停, $"平台2{e_LabelingFlow.ToString()}:移至拍照安全位X");
                                                continue;
                                            }

                                            nres = Step_Labeling(e_Step_Label.移至拍照位, e_platePro.平台1);
                                            if (nres != 1)
                                            {
                                                MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:移至拍照位");
                                                continue;
                                            }
                                            //拍照1
                                            nres = Step_Labeling(e_Step_Label.拍照, e_platePro.平台1);
                                            if (nres != 1)
                                            {
                                                MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:拍照");
                                                continue;
                                            }

                                            //右工位移到下相机上方并拍照2
                                            nres = Step_Labeling(e_Step_Label.移至拍照安全位X, e_platePro.平台1);
                                            if (nres != 1)
                                            {
                                                MachineState(e_MachineStatus.异常急停, $"平台1{e_LabelingFlow.ToString()}:移至拍照安全位X");
                                                continue;
                                            }

                                            nres = Step_Labeling(e_Step_Label.移至拍照位, e_platePro.平台2);
                                            if (nres != 1)
                                            {
                                                MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:移至拍照位");
                                                continue;
                                            }
                                            //拍照2
                                            nres = Step_Labeling(e_Step_Label.拍照, e_platePro.平台2);
                                            if (nres != 1)
                                            {
                                                MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:拍照");
                                                continue;
                                            }

                                            if (tempPlate == e_platePro.双平台有)
                                            {
                                                if (!Input_CardEx1[(int)e_input_extCard1.飞达1平台有料] && !Input_CardEx1[(int)e_input_extCard1.飞达2平台有料])
                                                {
                                                    GlobalVar.isFlying1OK = false;
                                                    GlobalVar.isFlying2OK = false;
                                                    GlobalVar.IsflyStart1 = true;
                                                    GlobalVar.IsflyStart2 = true;
                                                }
                                                else if (!Input_CardEx1[(int)e_input_extCard1.飞达1平台有料])//平台1
                                                {
                                                    GlobalVar.isFlying1OK = false;
                                                    GlobalVar.IsflyStart1 = true;
                                                }
                                                else if (!Input_CardEx1[(int)e_input_extCard1.飞达2平台有料])//平台2
                                                {
                                                    GlobalVar.isFlying2OK = false;
                                                    GlobalVar.IsflyStart2 = true;
                                                }
                                            }
                                            
                                        }
                                        else if (tempPlate == e_platePro.平台1)
                                        {
                                            camera1Time++;
                                            nres = Step_Labeling(e_Step_Label.移至拍照安全位X, e_platePro.平台2);
                                            if (nres != 1)
                                            {
                                                MachineState(e_MachineStatus.异常急停, $"平台2{e_LabelingFlow.ToString()}:移至拍照安全位X");
                                                continue;
                                            }

                                            nres = Step_Labeling(e_Step_Label.移至拍照位, tempPlate);
                                            if (nres != 1)
                                            {
                                                MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:移至拍照位");
                                                continue;
                                            }
                                            if (tempPlate == e_platePro.平台1 && !Input_CardEx1[(int)e_input_extCard1.飞达1平台有料])
                                            {
                                                //    if (nairAll!=(int)e_airResult.平台1已吸有料)
                                                {
                                                    GlobalVar.isFlying1OK = false;
                                                    GlobalVar.IsflyStart1 = true;
                                                }
                                            }
                                            //拍照1
                                            nres = Step_Labeling(e_Step_Label.拍照, tempPlate);
                                            if (nres != 1)
                                            {
                                                MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:拍照");
                                                continue;
                                            }

                                        }
                                        else if (tempPlate == e_platePro.平台2)
                                        {
                                            camera2Time++;
                                            nres = Step_Labeling(e_Step_Label.移至拍照安全位X, e_platePro.平台1);
                                            if (nres != 1)
                                            {
                                                MachineState(e_MachineStatus.异常急停, $"平台1{e_LabelingFlow.ToString()}:移至拍照安全位X");
                                                continue;
                                            }

                                            nres = Step_Labeling(e_Step_Label.移至拍照位, tempPlate);
                                            if (nres != 1)
                                            {
                                                MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:移至拍照位");
                                                continue;
                                            }
                                            if (tempPlate == e_platePro.平台2 && !Input_CardEx1[(int)e_input_extCard1.飞达2平台有料])
                                            {
                                                //     if (nairAll != (int)e_airResult.平台2已吸有料)
                                                {
                                                    GlobalVar.isFlying2OK = false;
                                                    GlobalVar.IsflyStart2 = true;
                                                }
                                            }
                                            //拍照2
                                            nres = Step_Labeling(e_Step_Label.拍照, tempPlate);
                                            if (nres != 1)
                                            {
                                                MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:拍照");
                                                continue;
                                            }
                                        }
                                        sw_Scan.Restart();
                                        e_LabelingFlow = e_Flow_Labeling.等待拍照结果;
                                    }
                                    break;
                                case e_Flow_Labeling.等待拍照结果:
                                    {
                                        if (GlobalVar.IsOldTest || CMachine.Instance.IsTestModel)
                                        {
                                            e_LabelingFlow = e_Flow_Labeling.定位OK待放标签;
                                            break;
                                        }

                                        if (sw_Scan.ElapsedMilliseconds > 8000)
                                        {
                                            sw_Scan.Restart();
                                            GlobalVar.e_Camera_Pos1 = e_Camera_Pos.已拍照NG;
                                            GlobalVar.e_Camera_Pos2 = e_Camera_Pos.已拍照NG;
                                            GlobalVar.IsProccessed1 = true;
                                            GlobalVar.IsProccessed2 = true;
                                            if (1 != GlobalMotion.TipInfo($"等待拍照结果超时8秒, 拍照NG处理  是:继续   否急停"))
                                            {
                                                MachineState(e_MachineStatus.异常急停, "双平台拍照超时11秒   拍照NG处理");
                                                break;
                                            }
                                        }

                                        if (curPlate == e_platePro.双平台有)
                                        {
                                            if (GlobalVar.IsProccessed1 && GlobalVar.IsProccessed2)
                                            {
                                                IsPlate1First = false;
                                                IsPlate2First = false;

                                                if (GlobalVar.e_Camera_Pos1 == e_Camera_Pos.已拍照NG && GlobalVar.e_Camera_Pos2 == e_Camera_Pos.已拍照NG)
                                                {
                                                    var tempPlate = curPlate;
                                                    if (camera1Time >= GlobalVar.userConfig.CameraNGTime || camera2Time >= GlobalVar.userConfig.CameraNGTime)
                                                    {
                                                        var msg = $"双平台拍照NG超过{GlobalVar.userConfig.CameraNGTime}次";
                                                        if (1 == GlobalMotion.TipInfo($"{msg}，是否继续"))
                                                        {

                                                        }
                                                        else
                                                        {
                                                            MachineState(e_MachineStatus.异常急停, $"{curPlate.ToString()}{e_LabelingFlow.ToString()}:{msg}");
                                                            continue;
                                                        }
                                                    }
                                                    var nres = Step_Labeling(e_Step_Label.移至拍照NG位上方, tempPlate);
                                                    if (nres != 1)
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"{curPlate.ToString()}{e_LabelingFlow.ToString()}:移至拍照NG位上方");
                                                        continue;
                                                    }

                                                    #region NG取标状态
                                                    bool isNglableOK = false;
                                                    for (int m = 0; m < GlobalVar.userConfig.getLabelNGTimes; m++)
                                                    {
                                                        if (IsNGlabelOk() != 1 || IsNGlabelPosExist() != 1)
                                                        {
                                                            var res1 = Step_Labeling(e_Step_Label.吸标NG旋转到取标位, e_platePro.双平台有);
                                                            if (res1 != 1)
                                                            {
                                                                MachineState(e_MachineStatus.异常急停, $"{e_platePro.双平台有.ToString()}{e_LabelingFlow.ToString()}:吸标NG抬起到取标位");
                                                                break;
                                                            }
                                                        }
                                                        else
                                                        {
                                                            isNglableOK = true;
                                                            break;
                                                        }
                                                    }
                                                    if (!isNglableOK)
                                                        continue;
                                                    #endregion
                                                    nres = Step_Labeling(e_Step_Label.取标气缸下压, tempPlate);
                                                    if (nres != 1)
                                                    {
                                                        if (MachineState(e_MachineStatus.异常急停, $"{curPlate.ToString()}{e_LabelingFlow.ToString()}:取标气缸下压") == -1)
                                                            continue;
                                                    }
                                                    nres = Step_Labeling(e_Step_Label.拍照NG位向下移动, e_platePro.平台1);
                                                    if (nres != 1)
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"{curPlate.ToString()}{e_LabelingFlow.ToString()}:拍照NG位向下移动");
                                                        continue;
                                                    }
                                                    nres = Step_Labeling(e_Step_Label.放标签破真空, tempPlate);
                                                    if (nres != 1)
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"{curPlate.ToString()}{e_LabelingFlow.ToString()}:放标签破真空");
                                                        continue;
                                                    }
                                                    nres = Step_Labeling(e_Step_Label.移至拍照NG位上方, tempPlate);
                                                    if (nres != 1)
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"{curPlate.ToString()}{e_LabelingFlow.ToString()}:移至拍照NG位上方");
                                                        continue;
                                                    }
                                                    nres = Step_Labeling(e_Step_Label.取标气缸抬起, tempPlate);
                                                    if (nres != 1)
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"{curPlate.ToString()}{e_LabelingFlow.ToString()}:取标气缸抬起");
                                                        continue;
                                                    }
                                                    if (GlobalVar.e_Camera_Pos1 == e_Camera_Pos.已拍照NG)
                                                    {
                                                        IsPlate1First = false;
                                                        IsPlate2First = false;
                                                        GlobalVar.IsProccessed1 = false;
                                                        GlobalVar.IsProccessed2 = false;
                                                        e_LabelingFlow = e_Flow_Labeling.取标签;
                                                    }
                                                }
                                                else if (GlobalVar.e_Camera_Pos1 == e_Camera_Pos.已拍照NG && !CMachine.Instance.IsTestModel)
                                                {
                                                    var tempPlate = e_platePro.平台1;
                                                    if (camera1Time >= GlobalVar.userConfig.CameraNGTime)
                                                    {
                                                        var msg = $"平台1 拍照NG超过{GlobalVar.userConfig.CameraNGTime}次";
                                                        if (1 == GlobalMotion.TipInfo($"{msg}，是否继续"))
                                                        {

                                                        }
                                                        else
                                                        {
                                                            MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:{msg}");
                                                            continue;
                                                        }
                                                    }
                                                    var nres = Step_Labeling(e_Step_Label.移至拍照NG位上方, tempPlate);
                                                    if (nres != 1)
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:移至拍照NG位上方");
                                                        continue;
                                                    }
                                                    #region NG取标状态
                                                    bool isNglableOK = false;
                                                    for (int m = 0; m < GlobalVar.userConfig.getLabelNGTimes; m++)
                                                    {
                                                        if (IsNGlabelOk() != 1 || IsNGlabelPosExist() != 1)
                                                        {
                                                            var res1 = Step_Labeling(e_Step_Label.吸标NG旋转到取标位, e_platePro.双平台有);
                                                            if (res1 != 1)
                                                            {

                                                                MachineState(e_MachineStatus.异常急停, $"{e_platePro.双平台有.ToString()}{e_LabelingFlow.ToString()}:吸标NG抬起到取标位");
                                                                break;
                                                            }
                                                        }
                                                        else
                                                        {
                                                            isNglableOK = true;
                                                            break;
                                                        }
                                                    }
                                                    if (!isNglableOK)
                                                        continue;
                                                    #endregion
                                                    nres = Step_Labeling(e_Step_Label.取标气缸下压, tempPlate);
                                                    if (nres != 1)
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:取标气缸下压");
                                                        continue;
                                                    }
                                                    nres = Step_Labeling(e_Step_Label.拍照NG位向下移动, tempPlate);
                                                    if (nres != 1)
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:拍照NG位向下移动");
                                                        continue;
                                                    }
                                                    nres = Step_Labeling(e_Step_Label.放标签破真空, tempPlate);
                                                    if (nres != 1)
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:放标签破真空");
                                                        continue;
                                                    }
                                                    nres = Step_Labeling(e_Step_Label.移至拍照NG位上方, tempPlate);
                                                    if (nres != 1)
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:移至拍照NG位上方");
                                                        continue;
                                                    }
                                                    nres = Step_Labeling(e_Step_Label.取标气缸抬起, tempPlate);
                                                    if (nres != 1)
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:取标气缸抬起");
                                                        continue;
                                                    }
                                                    if (GlobalVar.e_Camera_Pos2 == e_Camera_Pos.已拍照OK)
                                                    {
                                                        GlobalVar.IsProccessed1 = false;
                                                        IsPlate1First = true;
                                                        e_LabelingFlow = e_Flow_Labeling.取标签;
                                                    }
                                                }
                                                else if (GlobalVar.e_Camera_Pos2 == e_Camera_Pos.已拍照NG && !CMachine.Instance.IsTestModel)
                                                {
                                                    var tempPlate = e_platePro.平台2;
                                                    if (camera2Time >= GlobalVar.userConfig.CameraNGTime)
                                                    {
                                                        var msg = $"平台2拍照NG超过{GlobalVar.userConfig.CameraNGTime}次";
                                                        if (1 == GlobalMotion.TipInfo($"{msg}，是否继续"))
                                                        {

                                                        }
                                                        else
                                                        {
                                                            MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:{msg}");
                                                            continue;
                                                        }
                                                    }
                                                    var nres = Step_Labeling(e_Step_Label.移至拍照NG位上方, tempPlate);
                                                    if (nres != 1)
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:移至拍照NG位");
                                                        continue;
                                                    }

                                                    #region NG取标状态
                                                    bool isNglableOK = false;
                                                    for (int m = 0; m < GlobalVar.userConfig.getLabelNGTimes; m++)
                                                    {
                                                        if (IsNGlabelOk() != 1 || IsNGlabelPosExist() != 1)
                                                        {
                                                            var res1 = Step_Labeling(e_Step_Label.吸标NG旋转到取标位, e_platePro.双平台有);
                                                            if (res1 != 1)
                                                            {

                                                                MachineState(e_MachineStatus.异常急停, $"{e_platePro.双平台有.ToString()}{e_LabelingFlow.ToString()}:吸标NG抬起到取标位");
                                                                break;
                                                            }
                                                        }
                                                        else
                                                        {
                                                            isNglableOK = true;
                                                            break;
                                                        }
                                                    }
                                                    if (!isNglableOK)
                                                        continue;
                                                    #endregion
                                                    nres = Step_Labeling(e_Step_Label.取标气缸下压, tempPlate);
                                                    if (nres != 1)
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:取标气缸下压");
                                                        continue;
                                                    }
                                                    nres = Step_Labeling(e_Step_Label.拍照NG位向下移动, tempPlate);
                                                    if (nres != 1)
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:移至拍照NG位");
                                                        continue;
                                                    }
                                                    nres = Step_Labeling(e_Step_Label.放标签破真空, tempPlate);
                                                    if (nres != 1)
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:放标签破真空");
                                                        continue;
                                                    }
                                                    nres = Step_Labeling(e_Step_Label.移至拍照NG位上方, tempPlate);
                                                    if (nres != 1)
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:移至拍照NG位");
                                                        continue;
                                                    }
                                                    nres = Step_Labeling(e_Step_Label.取标气缸抬起, tempPlate);
                                                    if (nres != 1)
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:取标气缸抬起");
                                                        continue;
                                                    }
                                                    if (GlobalVar.e_Camera_Pos1 != e_Camera_Pos.已拍照NG)
                                                    {
                                                        IsPlate2First = true;
                                                        GlobalVar.IsProccessed2 = false;
                                                        e_LabelingFlow = e_Flow_Labeling.取标签;
                                                    }
                                                    else if (GlobalVar.e_Camera_Pos1 == e_Camera_Pos.已拍照NG)
                                                    {
                                                        GlobalVar.IsProccessed1 = false;
                                                        GlobalVar.IsProccessed2 = false;
                                                        e_LabelingFlow = e_Flow_Labeling.取标签;
                                                    }
                                                }
                                                else if ((GlobalVar.e_Camera_Pos1 == e_Camera_Pos.已拍照OK && GlobalVar.e_Camera_Pos2 == e_Camera_Pos.已拍照OK) || CMachine.Instance.IsTestModel)
                                                {
                                                    e_LabelingFlow = e_Flow_Labeling.定位OK待放标签;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (GlobalVar.IsProccessed1)
                                            {
                                                GlobalVar.IsProccessed1 = false;
                                                //单平台1拍照NG
                                                if (GlobalVar.e_Camera_Pos1 == e_Camera_Pos.已拍照NG)
                                                {
                                                    var tempPlate = e_platePro.平台1;
                                                    if (camera1Time >= GlobalVar.userConfig.CameraNGTime)
                                                    {
                                                        camera1Time = 0;
                                                        var msg = $"平台1拍照NG超过{GlobalVar.userConfig.CameraNGTime}次";
                                                        if (1 == GlobalMotion.TipInfo($"{msg}，是否继续"))
                                                        {

                                                        }

                                                    }

                                                    var nres = Step_Labeling(e_Step_Label.移至拍照NG位上方, tempPlate);
                                                    if (nres != 1)
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:移至拍照NG位上方");
                                                        continue;
                                                    }

                                                    #region NG取标状态
                                                    bool isNglableOK = false;
                                                    for (int m = 0; m < GlobalVar.userConfig.getLabelNGTimes; m++)
                                                    {
                                                        if (IsNGlabelOk() != 1 || IsNGlabelPosExist() != 1)
                                                        {
                                                            var res1 = Step_Labeling(e_Step_Label.吸标NG旋转到取标位, e_platePro.双平台有);
                                                            if (res1 != 1)
                                                            {

                                                                MachineState(e_MachineStatus.异常急停, $"{e_platePro.双平台有.ToString()}{e_LabelingFlow.ToString()}:吸标NG抬起到取标位");
                                                                break;
                                                            }
                                                        }
                                                        else
                                                        {
                                                            isNglableOK = true;
                                                            break;
                                                        }
                                                    }
                                                    if (!isNglableOK)
                                                        continue;
                                                    #endregion
                                                    nres = Step_Labeling(e_Step_Label.取标气缸下压, tempPlate);
                                                    if (nres != 1)
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:取标气缸下压");
                                                        continue;
                                                    }
                                                    nres = Step_Labeling(e_Step_Label.拍照NG位向下移动, tempPlate);
                                                    if (nres != 1)
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:拍照NG位向下移动");
                                                        continue;
                                                    }
                                                    nres = Step_Labeling(e_Step_Label.放标签破真空, tempPlate);
                                                    if (nres != 1)
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:放标签破真空");
                                                        continue;
                                                    }
                                                    nres = Step_Labeling(e_Step_Label.取标气缸抬起, tempPlate);
                                                    if (nres != 1)
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:取标气缸抬起");
                                                        continue;
                                                    }
                                                    nres = Step_Labeling(e_Step_Label.移至拍照NG位上方, tempPlate);
                                                    if (nres != 1)
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:移至拍照NG位上方");
                                                        continue;
                                                    }
                                                    e_LabelingFlow = e_Flow_Labeling.取标签;
                                                }
                                                //单平台1拍照OK
                                                else if (GlobalVar.e_Camera_Pos1 == e_Camera_Pos.已拍照OK)
                                                {
                                                    e_LabelingFlow = e_Flow_Labeling.定位OK待放标签;
                                                }
                                            }

                                            if (GlobalVar.IsProccessed2)
                                            {
                                                GlobalVar.IsProccessed2 = false;
                                                //单平台2拍照NG
                                                if (GlobalVar.e_Camera_Pos2 == e_Camera_Pos.已拍照NG)
                                                {
                                                    var tempPlate = e_platePro.平台2;
                                                    if (camera2Time >= GlobalVar.userConfig.CameraNGTime)
                                                    {
                                                        camera2Time = 0;
                                                        var msg = $"平台2拍照NG超过{GlobalVar.userConfig.CameraNGTime}次";
                                                        if (1 == GlobalMotion.TipInfo($"{msg}，是否继续"))
                                                        {

                                                        }
                                                        //else
                                                        //{
                                                        //    MachineState(e_MachineStatus.异常急停, $"{tempPlate.ToString()}{e_LabelingFlow.ToString()}:{msg}");
                                                        //    continue;
                                                        //}
                                                    }
                                                    var nres = Step_Labeling(e_Step_Label.移至拍照NG位上方, tempPlate);
                                                    if (nres != 1)
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:移至拍照NG位上方");
                                                        continue;
                                                    }

                                                    #region NG取标状态
                                                    bool isNglableOK = false;
                                                    for (int m = 0; m < GlobalVar.userConfig.getLabelNGTimes; m++)
                                                    {
                                                        if (IsNGlabelOk() != 1 || IsNGlabelPosExist() != 1)
                                                        {
                                                            var res1 = Step_Labeling(e_Step_Label.吸标NG旋转到取标位, e_platePro.双平台有);
                                                            if (res1 != 1)
                                                            {

                                                                MachineState(e_MachineStatus.异常急停, $"{e_platePro.双平台有.ToString()}{e_LabelingFlow.ToString()}:吸标NG抬起到取标位");
                                                                break;
                                                            }
                                                        }
                                                        else
                                                        {
                                                            isNglableOK = true;
                                                            break;
                                                        }
                                                    }
                                                    if (!isNglableOK)
                                                        continue;
                                                    #endregion
                                                    nres = Step_Labeling(e_Step_Label.取标气缸下压, tempPlate);
                                                    if (nres != 1)
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:取标气缸下压");
                                                        continue;
                                                    }
                                                    nres = Step_Labeling(e_Step_Label.拍照NG位向下移动, tempPlate);
                                                    if (nres != 1)
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:拍照NG位向下移动");
                                                        continue;
                                                    }
                                                    nres = Step_Labeling(e_Step_Label.放标签破真空, tempPlate);
                                                    if (nres != 1)
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:放标签破真空");
                                                        continue;
                                                    }
                                                    nres = Step_Labeling(e_Step_Label.移至拍照NG位上方, tempPlate);
                                                    if (nres != 1)
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:移至拍照NG位上方");
                                                        continue;
                                                    }
                                                    nres = Step_Labeling(e_Step_Label.取标气缸抬起, tempPlate);
                                                    if (nres != 1)
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:取标气缸抬起");
                                                        continue;
                                                    }
                                                    e_LabelingFlow = e_Flow_Labeling.取标签;
                                                }
                                                //单平台2拍照OK
                                                else if (GlobalVar.e_Camera_Pos2 == e_Camera_Pos.已拍照OK)
                                                {
                                                    e_LabelingFlow = e_Flow_Labeling.定位OK待放标签;
                                                }
                                            }
                                        }
                                    }
                                    break;
                                case e_Flow_Labeling.定位OK待放标签:///到这里一定是两个OK
                                    {
                                        if (curPlate == e_platePro.双平台有)
                                        {
                                            camera1Time = 0;
                                            camera2Time = 0;
                                            var tempPlate1 = e_platePro.平台1;
                                            var nres = Step_Labeling(e_Step_Label.移至拍照安全位X, e_platePro.平台2);
                                            if (nres != 1)
                                            {
                                                MachineState(e_MachineStatus.异常急停, $"平台2{e_LabelingFlow.ToString()}:移至拍照安全位X");
                                                continue;
                                            }
                                            nres = Step_Labeling(e_Step_Label.移至OK位上方, tempPlate1);
                                            if (nres != 1)
                                            {
                                                MachineState(e_MachineStatus.异常急停, $"{tempPlate1.ToString()}{e_LabelingFlow.ToString()}:移至OK位上方");
                                                continue;
                                            }
                                            e_LabelingFlow = e_Flow_Labeling.等待开始检测产品信号;
                                        }
                                        else if (curPlate == e_platePro.平台1)
                                        {
                                            camera1Time = 0;

                                            var tempPlate1 = e_platePro.平台1;
                                            var nres = Step_Labeling(e_Step_Label.移至拍照安全位X, e_platePro.平台2);
                                            if (nres != 1)
                                            {
                                                MachineState(e_MachineStatus.异常急停, $"平台2{e_LabelingFlow.ToString()}:移至拍照安全位X");
                                                continue;
                                            }
                                            nres = Step_Labeling(e_Step_Label.移至OK位上方, tempPlate1);
                                            if (nres != 1)
                                            {
                                                MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:{tempPlate1.ToString()}移至OK位");
                                                continue;
                                            }
                                            e_LabelingFlow = e_Flow_Labeling.等待开始检测产品信号;
                                        }
                                        else if (curPlate == e_platePro.平台2)
                                        {
                                            camera2Time = 0;
                                            var tempPlate2 = e_platePro.平台2;
                                            var nres = Step_Labeling(e_Step_Label.移至拍照安全位X, e_platePro.平台1);
                                            if (nres != 1)
                                            {
                                                MachineState(e_MachineStatus.异常急停, $"平台1{e_LabelingFlow.ToString()}:移至拍照安全位X");
                                                continue;
                                            }
                                            nres = Step_Labeling(e_Step_Label.移至OK位上方, tempPlate2);
                                            if (nres != 1)
                                            {
                                                MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:{tempPlate2.ToString()}移至OK位上方");
                                                continue;
                                            }
                                            e_LabelingFlow = e_Flow_Labeling.等待开始检测产品信号;
                                        }
                                        GlobalVar.displayCycleTime_label_STOP?.Invoke();

                                    }
                                    break;
                                case e_Flow_Labeling.等待开始检测产品信号:
                                    {
                                        ///等待开始检测产品信号
                                        if (GlobalVar.Label_Start || GlobalVar.IsOldTest || CMachine.Instance.IsTestModel)
                                        {
                                            GlobalVar.displayCycleTime_Label?.Invoke();
                                            GlobalVar.StartTime_Label = DateTime.Now;
                                            GlobalVar.Label_Start = false;
                                            e_LabelingFlow = e_Flow_Labeling.检查产品有无;

                                            IsPlate1First = false;
                                            IsPlate2First = false;

                                            GlobalVar.LabelFinshed = false;
                                            GlobalVar.IsProccessed1 = false;
                                            GlobalVar.IsProccessed2 = false;

                                            if (GlobalVar.Label_Start && GlobalVar.Label_pros.Count==0)
                                            {
                                                GlobalVar.Label_pros.Clear();
                                                GlobalVar.Label_pros.Add(new ProductInfo()
                                                {
                                                    LaserTime = DateTime.Now,
                                                    typeName = GlobalVar.closeSave.CurrentTypeName,
                                                    ProId = "O1",
                                                    ProNo = 1,
                                                    IsProcessAlarm = 1,
                                                    Result_up = e_Result.进料OK.ToString(),

                                                });
                                                GlobalVar.Label_pros.Add(new ProductInfo()
                                                {
                                                    LaserTime = DateTime.Now,
                                                    typeName = GlobalVar.closeSave.CurrentTypeName,
                                                    ProId = "O1",
                                                    ProNo = 2,
                                                    IsProcessAlarm = 1,
                                                    Result_up = e_Result.进料OK.ToString()
                                                });
                                            }
                                        }
                                    }
                                    break;
                                case e_Flow_Labeling.治具定位:
                                    if (GlobalVar.userConfig.IsPosAfterLabel || GlobalVar.userConfig.IsCheckCutResult)
                                    {
                                        var nres = GlobalMotion.Step_Labeling(e_Step_Label.移至拍照安全位X, e_platePro.双平台有);
                                        if (nres != 1)
                                        {
                                            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标X1下].PointMove(-50, true);
                                            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标X2上].PointMove(-50, true);
                                            //nres = Step_Labeling(e_Step_Label.移至拍照位, e_platePro.双平台有);
                                            //if (nres != 1)
                                            //{
                                            //    MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:移至拍照位");
                                            //    continue;
                                            //}
                                            MachineState(e_MachineStatus.异常急停, $"{e_platePro.双平台有.ToString()}{e_LabelingFlow.ToString()}:移至拍照安全位X");
                                            continue;
                                        }
                                        nres = GlobalMotion.Step_Labeling(e_Step_Label.移至拍照检测位);
                                        if (nres != 1)
                                        {
                                            MachineState(e_MachineStatus.异常急停, $"{curPlate.ToString()}{e_LabelingFlow.ToString()}:移至拍照检测位");
                                            continue;
                                        }

                                        //拍照获取位置偏差
                                        nres = Step_Labeling(e_Step_Label.贴标前定位拍照, curPlate);
                                        if (nres != 1)
                                        {
                                            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标X1下].PointMove(-50, true);
                                            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标X2上].PointMove(-50, true);
                                            MachineState(e_MachineStatus.异常急停, $"{curPlate.ToString()}{e_LabelingFlow.ToString()}:贴标前定位拍照");
                                            continue;
                                        }

                                        //Task.Run(()=>
                                        //{
                                        //    GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标X1下].PointMove(-50, true);
                                        //    GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标X2上].PointMove(-50, true);
                                        //});
                                        sw_Scan.Restart();
                                        e_LabelingFlow = e_Flow_Labeling.等待治具定位结果;

                                    }
                                    else
                                        e_LabelingFlow = e_Flow_Labeling.放标签;
                                    sw_Scan.Restart();
                                    break;
                                case e_Flow_Labeling.等待治具定位结果:
                                    { 
                                        if (sw_Scan.ElapsedMilliseconds > 15000&&false)
                                        {
                                            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标X1下].PointMove(-50, true);
                                            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标X2上].PointMove(-50, true);
                                         
                                            sw_Scan.Restart(); 
                                            if (1 != GlobalMotion.TipInfo($"等待治具定位结果超时8秒, 拍照NG处理  是:继续   否急停"))
                                            {
                                                MachineState(e_MachineStatus.异常急停, "双平台拍照超时8秒   拍照NG处理");
                                                break;
                                            }

                                            GlobalVar.e_Camera_LabelPos1 = e_Camera_Pos.已拍照NG;
                                            GlobalVar.e_Camera_LabelPos1 = e_Camera_Pos.已拍照NG;

                                            Step_Labeling(e_Step_Label.贴标前定位拍照, curPlate);
                                        }

                                        if (GlobalVar.userConfig.IsCheckCutResult)
                                        {
                                            if (curPlate == e_platePro.双平台有)
                                            {
                                                if (GlobalVar.e_Camera_Cut1 == e_Camera_Pos.未拍照 || GlobalVar.e_Camera_Cut2 == e_Camera_Pos.未拍照)
                                                {
                                                    continue;
                                                }
                                            }
                                            else
                                            {
                                                if (curPlate == e_platePro.平台1)
                                                {
                                                    if (GlobalVar.e_Camera_Cut1 == e_Camera_Pos.未拍照)
                                                    {
                                                        //GlobalVar.e_Camera_Cut2 = e_Camera_Pos.已拍照NG;
                                                        continue;
                                                    }
                                                }
                                                else if (curPlate == e_platePro.平台2)
                                                {
                                                    if (GlobalVar.e_Camera_Cut2 == e_Camera_Pos.未拍照)
                                                    {
                                                        //GlobalVar.e_Camera_Cut1 = e_Camera_Pos.已拍照NG;
                                                        continue;
                                                    }
                                                }
                                                //else
                                                //{
                                                //    GlobalVar.e_Camera_Cut2 = e_Camera_Pos.已拍照NG;
                                                //    GlobalVar.e_Camera_Cut1 = e_Camera_Pos.已拍照NG;
                                                //}
                                            }
                                        }

                                        if(GlobalVar.userConfig.IsPosAfterLabel)
                                        {
                                            if (curPlate == e_platePro.双平台有)
                                            {
                                                if (GlobalVar.e_Camera_LabelPos1 == e_Camera_Pos.未拍照 || GlobalVar.e_Camera_LabelPos2 == e_Camera_Pos.未拍照)
                                                {
                                                    continue;
                                                }
                                            }
                                            else
                                            {
                                                if (curPlate == e_platePro.平台1)
                                                {
                                                    if (GlobalVar.e_Camera_LabelPos1 == e_Camera_Pos.未拍照)
                                                    {
                                                        continue;
                                                    }
                                                }
                                                else if (curPlate == e_platePro.平台2)
                                                {
                                                    if (GlobalVar.e_Camera_LabelPos2 == e_Camera_Pos.未拍照)
                                                    {
                                                        continue;
                                                    }
                                                }

                                            }
                                        }

                                        switch (curPlate)
                                        {
                                            case e_platePro.平台1:
                                                if (GlobalVar.userConfig.IsCheckCutResult)
                                                {
                                                    if (GlobalVar.e_Camera_Cut1 == e_Camera_Pos.已拍照NG)
                                                    {
                                                        GlobalVar.Label_pros.ForEach(a =>
                                                        {
                                                            if (a.ProNo == 1)
                                                                a.Result_Cut = e_Result.撕膜NG.ToString();
                                                        });
                                                        e_LabelingFlow = e_Flow_Labeling.检查产品有无;
                                                        break;
                                                    }
                                                    if (GlobalVar.e_Camera_Cut1 == e_Camera_Pos.已拍照OK)
                                                    {

                                                        if (!GlobalVar.userConfig.IsPosAfterLabel)
                                                        {
                                                            e_LabelingFlow = e_Flow_Labeling.放标签;
                                                            break;
                                                        }
                                                    }
                                                }
                                                if (GlobalVar.userConfig.IsPosAfterLabel)
                                                {
                                                    if (GlobalVar.e_Camera_LabelPos1 == e_Camera_Pos.已拍照OK)
                                                    {
                                                        e_LabelingFlow = e_Flow_Labeling.放标签;
                                                    }
                                                    else if (GlobalVar.e_Camera_LabelPos1 == e_Camera_Pos.已拍照NG)
                                                    {
                                                        visionProc.LabelPostion1 = new Postion();
                                                        e_LabelingFlow = e_Flow_Labeling.检查产品有无;
                                                        break;
                                                    }
                                                }
                                                break;
                                            case e_platePro.平台2:
                                                if (GlobalVar.userConfig.IsCheckCutResult)
                                                {
                                                    if (GlobalVar.e_Camera_Cut2 == e_Camera_Pos.已拍照NG)
                                                    {
                                                        GlobalVar.Label_pros.ForEach(a =>
                                                        {
                                                            if (a.ProNo == 2)
                                                                a.Result_Cut = e_Result.撕膜NG.ToString();
                                                        });
                                                        e_LabelingFlow = e_Flow_Labeling.检查产品有无;
                                                        break;
                                                    }
                                                    if (GlobalVar.e_Camera_Cut2 == e_Camera_Pos.已拍照OK)
                                                    {

                                                        if (!GlobalVar.userConfig.IsPosAfterLabel)
                                                        {
                                                            e_LabelingFlow = e_Flow_Labeling.放标签;
                                                            break;
                                                        }
                                                    }
                                                }
                                                if (GlobalVar.userConfig.IsPosAfterLabel)
                                                {
                                                    if (GlobalVar.e_Camera_LabelPos2 == e_Camera_Pos.已拍照OK)
                                                    {
                                                        e_LabelingFlow = e_Flow_Labeling.放标签;
                                                    }
                                                    else if (GlobalVar.e_Camera_LabelPos2 == e_Camera_Pos.已拍照NG)
                                                    {
                                                        visionProc.LabelPostion2 = new Postion();
                                                        e_LabelingFlow = e_Flow_Labeling.检查产品有无;
                                                        break;
                                                    }
                                                }
                                                break;
                                            case e_platePro.双平台有:
                                                if (GlobalVar.userConfig.IsCheckCutResult)
                                                {
                                                    if (CMachine.Instance.IsTestModel)
                                                    {
                                                        GlobalVar.e_Camera_Cut1 = e_Camera_Pos.已拍照OK;
                                                        GlobalVar.e_Camera_Cut2 = e_Camera_Pos.已拍照OK;
                                                        GlobalVar.e_Camera_LabelPos1 = e_Camera_Pos.已拍照OK;
                                                        GlobalVar.e_Camera_LabelPos2 = e_Camera_Pos.已拍照OK;
                                                    }
                                                    if (GlobalVar.e_Camera_Cut1 != e_Camera_Pos.未拍照 && GlobalVar.e_Camera_Cut2 != e_Camera_Pos.未拍照)
                                                    {
                                                        bool IsCutOK = true;
                                                        if (GlobalVar.e_Camera_Cut1 == e_Camera_Pos.已拍照NG)
                                                        {
                                                            IsCutOK = false;
                                                            GlobalVar.Label_pros.ForEach(a =>
                                                            {
                                                                if (a.ProNo == 1)
                                                                    a.Result_Cut = e_Result.撕膜NG.ToString();
                                                            });
                                                        }
                                                        if (GlobalVar.e_Camera_Cut2 == e_Camera_Pos.已拍照NG)
                                                        {
                                                            IsCutOK = false;
                                                            GlobalVar.Label_pros.ForEach(a =>
                                                            {
                                                                if (a.ProNo == 2)
                                                                    a.Result_Cut = e_Result.撕膜NG.ToString();
                                                            });
                                                        }
                                                        if (!IsCutOK)
                                                        {
                                                            e_LabelingFlow = e_Flow_Labeling.检查产品有无;
                                                            break;
                                                        }
                                                        else
                                                        {
                                                            if (!GlobalVar.userConfig.IsPosAfterLabel)
                                                            {
                                                                e_LabelingFlow = e_Flow_Labeling.放标签;
                                                                break;
                                                            }
                                                        }

                                                    }
                                                }

                                                if (GlobalVar.userConfig.IsPosAfterLabel)
                                                {
                                                    if (GlobalVar.e_Camera_LabelPos1 != e_Camera_Pos.未拍照 && GlobalVar.e_Camera_LabelPos2 != e_Camera_Pos.未拍照)
                                                    {
                                                        e_LabelingFlow = e_Flow_Labeling.放标签;
                                                    }
                                                }
                                                break;
                                        }
                                    }
                                    break;
                                case e_Flow_Labeling.检查产品有无:
                                    {
                                        if (CMachine.Instance.IsTestModel)
                                        {
                                            e_LabelingFlow = e_Flow_Labeling.治具定位;
                                            curPlate = e_platePro.双平台有;
                                            break;
                                        }
                                        //手动贴
                                        if (GlobalVar.Label_Start && GlobalVar.Label_pros.Count == 0)
                                        {
                                            GlobalVar.Label_pros.Clear();
                                            GlobalVar.Label_pros.Add(new ProductInfo()
                                            {
                                                LaserTime = DateTime.Now,
                                                typeName = GlobalVar.closeSave.CurrentTypeName,
                                                ProId = "O1",
                                                ProNo = 1,
                                                IsProcessAlarm = 1,
                                                Result_up = e_Result.进料OK.ToString(),

                                            });
                                            GlobalVar.Label_pros.Add(new ProductInfo()
                                            {
                                                LaserTime = DateTime.Now,
                                                typeName = GlobalVar.closeSave.CurrentTypeName,
                                                ProId = "O1",
                                                ProNo = 2,
                                                IsProcessAlarm = 1,
                                                Result_up = e_Result.进料OK.ToString()
                                            });
                                        }

                                        if (IshavePro3 || IshavePro4)
                                        {
                                            if (IshavePro3 && IshavePro4)
                                            {
                                                curPlate = e_platePro.双平台有;
                                                
                                                var NGpro = GlobalVar.Label_pros.Where(a => a.Result_Cut.Contains("NG") || a.Result_up.Contains("NG")).ToList();
                                                if (NGpro == null || NGpro.Count == 0)
                                                {
                                                    if (GlobalVar.userConfig.isLabelFinishOK)
                                                    {
                                                        GlobalVar.Label_pros.ForEach(pro =>
                                                        {
                                                            if (curPlate == e_platePro.双平台有)
                                                            {

                                                                pro.Result_Label = e_Result.贴膜OK.ToString();
                                                            }
                                                            else
                                                            {
                                                                if (pro.ProNo == (int)curPlate)
                                                                {
                                                                    pro.Result_Label = e_Result.贴膜OK.ToString();
                                                                }
                                                            }
                                                        });

                                                        GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标X1下].PointMove(-50, true);
                                                        GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标X2上].PointMove(-50, true);
                                                        e_LabelingFlow = e_Flow_Labeling.放行治具;
                                                    }
                                                    else
                                                        e_LabelingFlow = e_Flow_Labeling.治具定位;
                                                }
                                                else if (NGpro.Count == 1)
                                                {
                                                    if (NGpro[0].ProNo == 1)
                                                        curPlate = e_platePro.平台1;
                                                    else
                                                        curPlate = e_platePro.平台2;
                                                    e_LabelingFlow = e_Flow_Labeling.进料NG放至NG输送上;
                                                }
                                                else if (NGpro.Count == 2)
                                                {
                                                    curPlate = e_platePro.双平台有;
                                                    e_LabelingFlow = e_Flow_Labeling.进料NG放至NG输送上;
                                                }
                                            }
                                            else if (IshavePro3 && !IshavePro4)
                                            {
                                                curPlate = e_platePro.平台1;
                                                var NGpro = GlobalVar.Label_pros.Where(a => a.ProNo == 1 && (a.Result_Cut.Contains("NG") || a.Result_up.Contains("NG") || a.Result_Cut.Contains("NG"))).ToList();
                                                if (NGpro == null || NGpro.Count == 0)
                                                {
                                                    if (GlobalVar.userConfig.isLabelFinishOK)
                                                    {
                                                        GlobalVar.Label_pros.ForEach(pro =>
                                                        {
                                                            if (pro.ProNo == (int)curPlate)
                                                            {
                                                                pro.Result_Label = e_Result.贴膜OK.ToString();
                                                            }
                                                        });
                                                        GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标X1下].PointMove(-50, true);
                                                        GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标X2上].PointMove(-50, true);
                                                        e_LabelingFlow = e_Flow_Labeling.放行治具;
                                                    }
                                                    else
                                                        e_LabelingFlow = e_Flow_Labeling.治具定位;
                                                }
                                                else if (NGpro.Count == 1)
                                                {
                                                    e_LabelingFlow = e_Flow_Labeling.进料NG放至NG输送上;
                                                }
                                            }
                                            else if (!IshavePro3 && IshavePro4)
                                            {
                                                curPlate = e_platePro.平台2;
                                                var NGpro = GlobalVar.Label_pros.Where(a => a.ProNo == 2 && (a.Result_Cut.Contains("NG") || a.Result_up.Contains("NG") || a.Result_Cut.Contains("NG"))).ToList();
                                                if (NGpro == null || NGpro.Count == 0)
                                                {
                                                    if (GlobalVar.userConfig.isLabelFinishOK)
                                                    {
                                                        GlobalVar.Label_pros.ForEach(pro =>
                                                        {
                                                            if (pro.ProNo == (int)curPlate)
                                                            {
                                                                pro.Result_Label = e_Result.贴膜OK.ToString();
                                                            }
                                                        });
                                                        GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标X1下].PointMove(-50, true);
                                                        GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标X2上].PointMove(-50, true);
                                                        e_LabelingFlow = e_Flow_Labeling.放行治具;
                                                    }
                                                    else
                                                        e_LabelingFlow = e_Flow_Labeling.治具定位;
                                                }
                                                else if (NGpro.Count == 1)
                                                {
                                                    GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标X1下].PointMove(-50, true);
                                                    GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标X2上].PointMove(-50, true);
                                                    e_LabelingFlow = e_Flow_Labeling.进料NG放至NG输送上;
                                                }
                                            }
                                            getLabelTimes = 0;

                                        }
                                        else
                                        {
                                            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标X1下].PointMove(-50, true);
                                            GlobalMotion.Card_1.AxisList[(int)e_card1_axis.贴标X2上].PointMove(-50, true);
                                            curPlate = e_platePro.双平台无;
                                            e_LabelingFlow = e_Flow_Labeling.放行治具;
                                        }

                                    }
                                    break;
                                case e_Flow_Labeling.进料NG放至NG输送上:
                                    {
                                        ///靶面两个移至安全位
                                        if (GlobalVar.userConfig.IsCheckCutResult)
                                        {
                                            if (GlobalVar.e_Camera_Cut1 == e_Camera_Pos.未拍照 || GlobalVar.e_Camera_Cut2 == e_Camera_Pos.未拍照)
                                            {
                                                continue;
                                            }
                                            if (GlobalVar.e_Camera_Cut1 == e_Camera_Pos.已拍照NG && 
                                                GlobalVar.e_Camera_Cut2 == e_Camera_Pos.已拍照NG)
                                            {
                                                curPlate = e_platePro.双平台有;
                                            }
                                            else
                                            {
                                                if (GlobalVar.e_Camera_Cut1 == e_Camera_Pos.已拍照NG)
                                                {
                                                    curPlate = e_platePro.平台1;
                                                }
                                                else if (GlobalVar.e_Camera_Cut2 == e_Camera_Pos.已拍照NG)
                                                {
                                                    curPlate = e_platePro.平台2;
                                                }
                                            }
                                        }
                                        ///移动至工装位///还有料就检测产品有无   没料就直接放行
                                        var nres = Step_Labeling(e_Step_Label.移至拍照安全位X, e_platePro.平台1);
                                        if (nres != 1)
                                        {
                                            MachineState(e_MachineStatus.异常急停, $"{e_platePro.平台1.ToString()}{e_LabelingFlow.ToString()}:移至拍照安全位X");
                                            continue;
                                        }
                                        nres = Step_Labeling(e_Step_Label.移至拍照安全位X, e_platePro.平台2);
                                        if (nres != 1)
                                        {
                                            MachineState(e_MachineStatus.异常急停, $"{e_platePro.平台2.ToString()}{e_LabelingFlow.ToString()}:移至拍照安全位X");
                                            continue;
                                        }

                                        nres = MutilStep_NGPut(curPlate);
                                        if (nres != 1)
                                        {
                                            MachineState(e_MachineStatus.异常急停, $"{curPlate.ToString()}{e_LabelingFlow.ToString()}:NG放工装位");
                                            continue;
                                        }

                                        if (curPlate== e_platePro.平台1)
                                        {//平台1 抛物料，平台2，继续贴
                                            curPlate = e_platePro.平台2;
                                            e_LabelingFlow = e_Flow_Labeling.放标签;
                                        }
                                        else if (curPlate == e_platePro.平台2)
                                        {//
                                            curPlate = e_platePro.平台1;
                                            e_LabelingFlow = e_Flow_Labeling.放标签;
                                        }
                                        else
                                        {
                                            e_LabelingFlow = e_Flow_Labeling.放行治具;
                                        }
                                    }
                                    break;
                                case e_Flow_Labeling.放标签:
                                    {
                                        if (curPlate == e_platePro.双平台有)
                                        {

                                            //if (GlobalVar.e_Camera_LabelPos1 == e_Camera_Pos.已拍照OK)
                                            {
                                                var tempPlate1 = e_platePro.平台1;
                                                var nres = Step_Labeling(e_Step_Label.移至拍照安全位X, e_platePro.平台2);
                                                if (nres != 1)
                                                {
                                                    MachineState(e_MachineStatus.异常急停, $"{e_platePro.平台2.ToString()}{e_LabelingFlow.ToString()}:移至拍照安全位X");
                                                    continue;
                                                }
                                                nres = Step_Labeling(e_Step_Label.移至OK位上方, tempPlate1);
                                                if (nres != 1)
                                                {
                                                    MachineState(e_MachineStatus.异常急停, $"{tempPlate1.ToString()}{e_LabelingFlow.ToString()}:移至OK位上方");
                                                    continue;
                                                }
                                                GlobalVar.air1down_start = true;
                                                nres = Step_Labeling(e_Step_Label.OK位向下移动, tempPlate1);
                                                if (nres != 1)
                                                {
                                                    MachineState(e_MachineStatus.异常急停, $"{tempPlate1.ToString()}{e_LabelingFlow.ToString()}:OK位向下移动");
                                                    continue;
                                                }
                                                waitforAir(false, tempPlate1);
                                                nres = Step_Labeling(e_Step_Label.放标签破真空, tempPlate1);
                                                if (nres != 1)
                                                {
                                                    MachineState(e_MachineStatus.异常急停, $"{tempPlate1.ToString()}{e_LabelingFlow.ToString()}:放标签破真空");
                                                    continue;
                                                }
                                                GlobalVar.air1up_start = true;
                                                nres = Step_Labeling(e_Step_Label.移至OK位上方, tempPlate1);
                                                if (nres != 1)
                                                {
                                                    MachineState(e_MachineStatus.异常急停, $"{tempPlate1.ToString()}{e_LabelingFlow.ToString()}:移至OK位上方");
                                                    continue;
                                                }
                                                waitforAir(true, tempPlate1);
                                            }
                                            //else
                                            //{
                                            //    displalyInfo.displayInfoMain("检测定位平台1 视觉检测NG，不贴膜");
                                            //}

                                            //if (GlobalVar.e_Camera_LabelPos2 == e_Camera_Pos.已拍照OK)
                                            {
                                                var tempPlate2 = e_platePro.平台2;
                                                var nres = Step_Labeling(e_Step_Label.移至拍照安全位X, e_platePro.平台1);
                                                if (nres != 1)
                                                {
                                                    MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:移至拍照安全位X");
                                                    continue;
                                                }

                                                nres = Step_Labeling(e_Step_Label.移至OK位上方, tempPlate2);
                                                if (nres != 1)
                                                {
                                                    MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:{tempPlate2.ToString()}移至OK位上方");
                                                    continue;
                                                }
                                                GlobalVar.air2down_start = true;
                                                nres = Step_Labeling(e_Step_Label.OK位向下移动, tempPlate2);
                                                if (nres != 1)
                                                {
                                                    MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:{tempPlate2.ToString()}OK位向下移动");
                                                    continue;
                                                }
                                                waitforAir(false, tempPlate2);
                                                nres = Step_Labeling(e_Step_Label.放标签破真空, tempPlate2);
                                                if (nres != 1)
                                                {
                                                    MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:{tempPlate2.ToString()}放标签破真空");
                                                    continue;
                                                }
                                                GlobalVar.air2up_start = true;
                                                nres = Step_Labeling(e_Step_Label.移至OK位上方, tempPlate2);
                                                if (nres != 1)
                                                {
                                                    MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:{tempPlate2.ToString()}移至OK位上方");
                                                    continue;
                                                }
                                                waitforAir(true, tempPlate2);
                                            }
                                            //else
                                            //{
                                            //    displalyInfo.displayInfoMain("检测定位平台2 视觉检测NG，不贴膜");
                                            //}

                                            e_LabelingFlow = e_Flow_Labeling.到贴标位拍照;
                                        }
                                        else if (curPlate == e_platePro.平台1)
                                        {
                                            //if (GlobalVar.e_Camera_LabelPos1 == e_Camera_Pos.已拍照OK)
                                            {
                                                var tempPlate1 = e_platePro.平台1;
                                                var nres = Step_Labeling(e_Step_Label.移至OK位上方, tempPlate1);
                                                if (nres != 1)
                                                {
                                                    MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:{tempPlate1.ToString()}移至OK位上方");
                                                    continue;
                                                }
                                                nres = Step_Labeling(e_Step_Label.取标气缸下压, tempPlate1);
                                                if (nres != 1)
                                                {
                                                    MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:{tempPlate1.ToString()}取标气缸下压");
                                                    continue;
                                                }
                                                nres = Step_Labeling(e_Step_Label.OK位向下移动, tempPlate1);
                                                if (nres != 1)
                                                {
                                                    MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:{tempPlate1.ToString()}OK位向下移动");
                                                    continue;
                                                }
                                                nres = Step_Labeling(e_Step_Label.放标签破真空, tempPlate1);
                                                if (nres != 1)
                                                {
                                                    MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:{tempPlate1.ToString()}放标签破真空");
                                                    continue;
                                                }
                                                nres = Step_Labeling(e_Step_Label.移至OK位上方, tempPlate1);
                                                if (nres != 1)
                                                {
                                                    MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:{tempPlate1.ToString()}移至OK位上方");
                                                    continue;
                                                }
                                                nres = Step_Labeling(e_Step_Label.取标气缸抬起, tempPlate1);
                                                if (nres != 1)
                                                {
                                                    MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:{tempPlate1.ToString()}取标气缸抬起");
                                                    continue;
                                                }
                                            }
                                            //else
                                            //{
                                            //    displalyInfo.displayInfoMain("检测定位平台1 视觉检测NG，不贴膜");
                                            //}
                                            e_LabelingFlow = e_Flow_Labeling.到贴标位拍照;
                                        }
                                        else if (curPlate == e_platePro.平台2)
                                        {
                                            //if (GlobalVar.e_Camera_LabelPos2 == e_Camera_Pos.已拍照OK)
                                            {
                                                var tempPlate2 = e_platePro.平台2;
                                                var nres = Step_Labeling(e_Step_Label.移至OK位上方, tempPlate2);
                                                if (nres != 1)
                                                {
                                                    MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:{tempPlate2.ToString()}移至OK位上方");
                                                    continue;
                                                }
                                                nres = Step_Labeling(e_Step_Label.取标气缸下压, tempPlate2);
                                                if (nres != 1)
                                                {
                                                    MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:{tempPlate2.ToString()}取标气缸下压");
                                                    continue;
                                                }
                                                nres = Step_Labeling(e_Step_Label.OK位向下移动, tempPlate2);
                                                if (nres != 1)
                                                {
                                                    MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:{tempPlate2.ToString()}OK位向下移动");
                                                    continue;
                                                }
                                                nres = Step_Labeling(e_Step_Label.放标签破真空, tempPlate2);
                                                if (nres != 1)
                                                {
                                                    MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:{tempPlate2.ToString()}放标签破真空");
                                                    continue;
                                                }
                                                nres = Step_Labeling(e_Step_Label.移至OK位上方, tempPlate2);
                                                if (nres != 1)
                                                {
                                                    MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:{tempPlate2.ToString()}移至OK位上方");
                                                    continue;
                                                }
                                                nres = Step_Labeling(e_Step_Label.取标气缸抬起, tempPlate2);
                                                if (nres != 1)
                                                {
                                                    MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:{tempPlate2.ToString()}取标气缸抬起");
                                                    continue;
                                                }
                                            }
                                            //else
                                            //{
                                            //    displalyInfo.displayInfoMain("检测定位平台2 视觉检测NG，不贴膜");
                                            //}
                                           
                                            e_LabelingFlow = e_Flow_Labeling.到贴标位拍照;
                                        }
                                    }
                                    break;
                                case e_Flow_Labeling.到贴标位拍照:
                                    {
                                        if (curPlate == e_platePro.平台1)
                                        {
                                            var nres = GlobalMotion.Step_Labeling(e_Step_Label.移至拍照安全位X, curPlate);
                                            if (nres != 1)
                                            {
                                                MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:{curPlate.ToString()}移至拍照安全位X");
                                                continue;
                                            }
                                            nres = GlobalMotion.Step_Labeling(e_Step_Label.移至拍照检测位);
                                            if (nres != 1)
                                            {
                                                MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:{curPlate.ToString()}移至拍照检测位");
                                                continue;
                                            }
                                            nres = GlobalMotion.Step_Labeling(e_Step_Label.拍照检测, curPlate);
                                            if (nres != 1)
                                            {
                                                MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:{curPlate.ToString()}拍照检测");
                                                continue;
                                            }
                                            e_LabelingFlow = e_Flow_Labeling.等待检测结果;
                                        }
                                        else if (curPlate == e_platePro.平台2)
                                        {
                                            var nres = GlobalMotion.Step_Labeling(e_Step_Label.移至拍照安全位X, curPlate);
                                            if (nres != 1)
                                            {
                                                MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:{curPlate.ToString()}移至拍照安全位X");
                                                continue;
                                            }
                                            nres = GlobalMotion.Step_Labeling(e_Step_Label.移至拍照检测位);
                                            if (nres != 1)
                                            {
                                                MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:{curPlate.ToString()}移至拍照检测位");
                                                continue;
                                            }
                                            nres = GlobalMotion.Step_Labeling(e_Step_Label.拍照检测, curPlate);
                                            if (nres != 1)
                                            {
                                                MachineState(e_MachineStatus.异常急停, $"{e_LabelingFlow.ToString()}:{curPlate.ToString()}拍照检测");
                                                continue;
                                            }
                                            e_LabelingFlow = e_Flow_Labeling.等待检测结果;
                                        }
                                        else if (curPlate == e_platePro.双平台有)
                                        {
                                            var nres = GlobalMotion.Step_Labeling(e_Step_Label.移至拍照安全位X, curPlate);
                                            if (nres != 1)
                                            {
                                                MachineState(e_MachineStatus.异常急停, $"{e_platePro.双平台有.ToString()}{e_LabelingFlow.ToString()}:移至拍照安全位X");
                                                continue;
                                            }
                                            nres = GlobalMotion.Step_Labeling(e_Step_Label.移至拍照检测位);
                                            if (nres != 1)
                                            {
                                                MachineState(e_MachineStatus.异常急停, $"{curPlate.ToString()}{e_LabelingFlow.ToString()}:移至拍照检测位");
                                                continue;
                                            }
                                            nres = GlobalMotion.Step_Labeling(e_Step_Label.拍照检测, curPlate);
                                            if (nres != 1)
                                            {
                                                MachineState(e_MachineStatus.异常急停, $"{curPlate.ToString()}{e_LabelingFlow.ToString()}:拍照检测");
                                                continue;
                                            }
                                            e_LabelingFlow = e_Flow_Labeling.等待检测结果;
                                        }
                                    }
                                    break;
                                case e_Flow_Labeling.等待检测结果:
                                    {
                                        if (curPlate == e_platePro.双平台有)
                                        {
                                            //检查是否有残胶
                                            if (GlobalVar.e_Camera_LabelPos1 == e_Camera_Pos.已拍照OK &&
                                                   GlobalVar.e_Camera_LabelPos2 == e_Camera_Pos.已拍照OK)
                                            {
                                                var nes = Step_Labeling(e_Step_Label.取标签吸真空, e_platePro.双平台有);
                                                if (nes != (int)e_airResult.双平台吸无料)
                                                {

                                                    if (GlobalMotion.TipInfo($"双平台 靶面上有残胶,请确认！是:继续   否急停") != 1)
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"双平台{e_LabelingFlow.ToString()}:靶面上有残胶");
                                                    }
                                                }
                                                Step_Labeling(e_Step_Label.放标签破真空, e_platePro.双平台有);
                                            }
                                            else if(GlobalVar.e_Camera_LabelPos1 == e_Camera_Pos.已拍照OK)
                                            {
                                                var nes = Step_Labeling(e_Step_Label.取标签吸真空, e_platePro.平台1);
                                                if (nes == 1)
                                                {

                                                    if (GlobalMotion.TipInfo($"双平台 靶面上有残胶,请确认！是:继续   否急停") != 1)
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"双平台{e_LabelingFlow.ToString()}:靶面上有残胶");
                                                    }
                                                }
                                                Step_Labeling(e_Step_Label.放标签破真空, e_platePro.平台1);
                                            }
                                            else if (GlobalVar.e_Camera_LabelPos2 == e_Camera_Pos.已拍照OK)
                                            {
                                                var nes = Step_Labeling(e_Step_Label.取标签吸真空, e_platePro.平台2);
                                                if (nes == 1)
                                                {

                                                    if (GlobalMotion.TipInfo($"双平台 靶面上有残胶,请确认！是:继续   否急停") != 1)
                                                    {
                                                        MachineState(e_MachineStatus.异常急停, $"双平台{e_LabelingFlow.ToString()}:靶面上有残胶");
                                                    }
                                                }
                                                Step_Labeling(e_Step_Label.放标签破真空, e_platePro.平台2);
                                            }
                                            

                                            if (GlobalVar.IsOldTest || GlobalVar.userConfig.IsLabelResultOk || CMachine.Instance.IsTestModel )
                                            {//强制OK
                                                GlobalVar.Label_pros.ForEach(a => a.Result_Label = e_Result.贴膜OK.ToString());
                                                e_LabelingFlow = e_Flow_Labeling.放行治具;
                                                break;
                                                //e_LabelingFlow = e_Flow_Labeling.贴标NG放至NG输送上;
                                            }
                                            else if (GlobalVar.e_Camera_Check1 != e_Camera_Pos.未拍照 && GlobalVar.e_Camera_Check2 != e_Camera_Pos.未拍照)
                                            {
                                                if (GlobalVar.e_Camera_Check1 == e_Camera_Pos.已拍照OK && GlobalVar.e_Camera_Check2 == e_Camera_Pos.已拍照OK)//全OK就直接放行
                                                {
                                                    bool isAllOk1 = false;
                                                    bool isAllOk2 = false;
                                                    //GlobalVar.Label_pros.ForEach(a =>
                                                    //{
                                                    //    if (a.ProNo == 1)
                                                    //    {
                                                    //        if (GlobalVar.e_Camera_LabelPos1 == e_Camera_Pos.已拍照OK)
                                                    //        {
                                                    //            var posMsg = "";
                                                    //            if (visionProc.ResultPlate1 != null)
                                                    //                posMsg += $"{visionProc.ResultPlate1.X.ToString("F02")}Y:{visionProc.ResultPlate1.Y.ToString("F02")},Angel:{visionProc.ResultPlate1.Angle.ToString("F02")}";
                                                    //            a.Result_Label = e_Result.贴膜OK.ToString() + posMsg;
                                                    //            isAllOk1 = true;
                                                    //        }
                                                    //        else
                                                    //            a.Result_Label = e_Result.贴膜NG.ToString();
                                                    //    }
                                                    //    else if (a.ProNo == 2)
                                                    //    {
                                                    //        if (GlobalVar.e_Camera_LabelPos2 == e_Camera_Pos.已拍照OK)
                                                    //        {
                                                    //            var posMsg = "";
                                                    //            if (visionProc.ResultPlate2 != null)
                                                    //                posMsg += $"{visionProc.ResultPlate2.X.ToString("F02")}Y:{visionProc.ResultPlate2.Y.ToString("F02")},Angel:{visionProc.ResultPlate2.Angle.ToString("F02")}";
                                                    //            a.Result_Label = e_Result.贴膜OK.ToString() + posMsg;
                                                    //            isAllOk2 = true;
                                                    //        }
                                                    //        else
                                                    //            a.Result_Label = e_Result.贴膜NG.ToString();
                                                    //    }
                                                    //});

                                                    //if (isAllOk1 && isAllOk2)
                                                    //{
                                                    //    e_LabelingFlow = e_Flow_Labeling.放行治具;
                                                    //}
                                                    //else
                                                    //{
                                                    //    e_LabelingFlow = e_Flow_Labeling.贴标NG放至NG输送上;
                                                    //}

                                                    GlobalVar.Label_pros.ForEach(a =>
                                                    {
                                                        var posMsg = "";

                                                        //if (GlobalVar.e_Camera_LabelPos1 == e_Camera_Pos.已拍照OK && GlobalVar.e_Camera_LabelPos2 == e_Camera_Pos.已拍照OK)
                                                        {
                                                            if (a.ProNo == 1)
                                                            {
                                                                if (visionProc.ResultPlate1 != null)
                                                                    posMsg += $"{visionProc.ResultPlate1.X.ToString("F02")}Y:{visionProc.ResultPlate1.Y.ToString("F02")},Angel:{visionProc.ResultPlate1.Angle.ToString("F02")}";
                                                            }
                                                            else if (a.ProNo == 2)
                                                            {
                                                                if (visionProc.ResultPlate2 != null)
                                                                    posMsg += $"{visionProc.ResultPlate2.X.ToString("F02")}Y:{visionProc.ResultPlate2.Y.ToString("F02")},Angel:{visionProc.ResultPlate2.Angle.ToString("F02")}";
                                                            }
                                                            a.Result_Label = e_Result.贴膜OK.ToString() ;
                                                        }

                                                        if (a.ProNo == 1)
                                                        {
                                                            if (visionProc.ResultPlate1 != null)
                                                                posMsg += $"{visionProc.ResultPlate1.X.ToString("F02")}Y:{visionProc.ResultPlate1.Y.ToString("F02")},Angel:{visionProc.ResultPlate1.Angle.ToString("F02")}";
                                                        }
                                                        else if (a.ProNo == 2)
                                                        {
                                                            if (visionProc.ResultPlate2 != null)
                                                                posMsg += $"{visionProc.ResultPlate2.X.ToString("F02")}Y:{visionProc.ResultPlate2.Y.ToString("F02")},Angel:{visionProc.ResultPlate2.Angle.ToString("F02")}";
                                                        }
                                                        a.Result_Label = e_Result.贴膜OK.ToString();
                                                    });
                                                    e_LabelingFlow = e_Flow_Labeling.放行治具;
                                                }
                                                else
                                                {
                                                    bool isAllOk1 = false;
                                                    bool isAllOk2 = false;
                                                    GlobalVar.Label_pros.ForEach(a =>
                                                    {
                                                        if (a.ProNo == 1)
                                                        {
                                                            if (GlobalVar.e_Camera_Check1 == e_Camera_Pos.已拍照OK)
                                                            {
                                                                var posMsg = "";
                                                                if (visionProc.ResultPlate1 != null)
                                                                    posMsg += $"{visionProc.ResultPlate1.X.ToString("F02")}Y:{visionProc.ResultPlate1.Y.ToString("F02")},Angel:{visionProc.ResultPlate1.Angle.ToString("F02")}";
                                                                a.Result_Label = e_Result.贴膜OK.ToString() + posMsg;
                                                            }
                                                            else
                                                            {
                                                                isAllOk1 = true;
                                                                a.Result_Label = e_Result.贴膜NG.ToString();
                                                            }
                                                               
                                                        }
                                                        else if (a.ProNo == 2)
                                                        {
                                                            if (GlobalVar.e_Camera_Check2 == e_Camera_Pos.已拍照OK)
                                                            {
                                                                var posMsg = "";
                                                                if (visionProc.ResultPlate2 != null)
                                                                    posMsg += $"{visionProc.ResultPlate2.X.ToString("F02")}Y:{visionProc.ResultPlate2.Y.ToString("F02")},Angel:{visionProc.ResultPlate2.Angle.ToString("F02")}";
                                                                a.Result_Label = e_Result.贴膜OK.ToString() + posMsg;
                                                            }
                                                            else
                                                            {
                                                                isAllOk2 = true;
                                                                a.Result_Label = e_Result.贴膜NG.ToString();
                                                            }
                                                               
                                                        }
                                                    });

                                                    e_LabelingFlow = e_Flow_Labeling.贴标NG放至NG输送上;
                                                }
                                            }
                                        }
                                        else if ((curPlate == e_platePro.平台1))
                                        {
                                            var nes = Step_Labeling(e_Step_Label.取标签吸真空, e_platePro.平台1);
                                            if (nes == (int)e_airResult.平台1已吸有料)
                                            {
                                                //GlobalVar.isPause = true;
                                                if (GlobalMotion.TipInfo($"平台1已吸有料 靶面上有残胶,请确认！是:继续   否急停") != 1)
                                                {
                                                    MachineState(e_MachineStatus.异常急停, $"平台1 {e_LabelingFlow.ToString()}:靶面上有残胶");
                                                }
                                                GlobalVar.isPause = false;
                                            }
                                            Step_Labeling(e_Step_Label.放标签破真空, e_platePro.平台1);

                                            if (GlobalVar.IsOldTest || GlobalVar.userConfig.IsLabelResultOk)
                                            {
                                                GlobalVar.Label_pros.ForEach(a =>
                                                {
                                                    if (a.ProNo == 1)
                                                        a.Result_Label = e_Result.贴膜OK.ToString();
                                                });
                                                e_LabelingFlow = e_Flow_Labeling.放行治具;
                                            }
                                            else if (GlobalVar.e_Camera_Check1 != e_Camera_Pos.未拍照)
                                            {
                                                if (GlobalVar.e_Camera_Check1 == e_Camera_Pos.已拍照OK)
                                                {
                                                    GlobalVar.Label_pros.ForEach(a =>
                                                    {
                                                        var posMsg = "";
                                                        if (a.ProNo == 1)
                                                        {
                                                            if (visionProc.ResultPlate1 != null)
                                                                posMsg += $"{visionProc.ResultPlate1.X.ToString("F02")}Y:{visionProc.ResultPlate1.Y.ToString("F02")},Angel:{visionProc.ResultPlate1.Angle.ToString("F02")}";
                                                            a.Result_Label = e_Result.贴膜OK.ToString() + posMsg;
                                                        }

                                                    });
                                                    if (GlobalVar.e_Camera_LabelPos1 == e_Camera_Pos.已拍照OK)
                                                    {
                                                        e_LabelingFlow = e_Flow_Labeling.放行治具;
                                                    }
                                                    else
                                                    {
                                                        GlobalVar.Label_pros.ForEach(a =>
                                                        {
                                                            if (a.ProNo == 1)
                                                                a.Result_Label = e_Result.贴膜NG.ToString();
                                                        });
                                                        e_LabelingFlow = e_Flow_Labeling.贴标NG放至NG输送上;
                                                    }
                                                }
                                                else
                                                {
                                                    GlobalVar.Label_pros.ForEach(a =>
                                                    {
                                                        if (a.ProNo == 1)
                                                            a.Result_Label = e_Result.贴膜NG.ToString();
                                                    });
                                                    e_LabelingFlow = e_Flow_Labeling.贴标NG放至NG输送上;
                                                }
                                            }
                                        }
                                        else if ((curPlate == e_platePro.平台2))
                                        {
                                            var nes = Step_Labeling(e_Step_Label.取标签吸真空, e_platePro.平台2);
                                            if (nes == (int)e_airResult.平台2已吸有料)
                                            {
                                                if (GlobalMotion.TipInfo($"平台2已吸有料 靶面上有残胶,请确认！是:继续   否急停") != 1)
                                                {
                                                    MachineState(e_MachineStatus.异常急停, $"平台2 {e_LabelingFlow.ToString()}:靶面上有残胶");
                                                }
                                            }
                                            Step_Labeling(e_Step_Label.放标签破真空, e_platePro.平台2);

                                            if (GlobalVar.IsOldTest || GlobalVar.userConfig.IsLabelResultOk)
                                            {
                                                GlobalVar.Label_pros.ForEach(a =>
                                                {
                                                    if (a.ProNo == 2)
                                                        a.Result_Label = e_Result.贴膜OK.ToString();
                                                });

                                                if (GlobalVar.e_Camera_LabelPos2 == e_Camera_Pos.已拍照OK)
                                                {
                                                    e_LabelingFlow = e_Flow_Labeling.放行治具;
                                                }
                                                else
                                                {
                                                    GlobalVar.Label_pros.ForEach(a =>
                                                    {
                                                        if (a.ProNo == 2)
                                                            a.Result_Label = e_Result.贴膜NG.ToString();
                                                    });
                                                    e_LabelingFlow = e_Flow_Labeling.贴标NG放至NG输送上;
                                                }
                                                
                                            }
                                            else if (GlobalVar.e_Camera_Check2 != e_Camera_Pos.未拍照)
                                            {
                                                if (GlobalVar.e_Camera_Check2 == e_Camera_Pos.已拍照OK)
                                                {
                                                    GlobalVar.Label_pros.ForEach(a =>
                                                    {
                                                        var posMsg = "";
                                                        if (a.ProNo == 2)
                                                        {
                                                            if (visionProc.ResultPlate2 != null)
                                                                posMsg += $"{visionProc.ResultPlate2.X.ToString("F02")}Y:{visionProc.ResultPlate2.Y.ToString("F02")},Angel:{visionProc.ResultPlate2.Angle.ToString("F02")}";
                                                            a.Result_Label = e_Result.贴膜OK.ToString() + posMsg;
                                                        }

                                                    });
                                                    e_LabelingFlow = e_Flow_Labeling.放行治具;
                                                }
                                                else
                                                {
                                                    GlobalVar.Label_pros.ForEach(a =>
                                                    {
                                                        if (a.ProNo == 2)
                                                            a.Result_Label = e_Result.贴膜NG.ToString();
                                                    });
                                                    e_LabelingFlow = e_Flow_Labeling.贴标NG放至NG输送上;
                                                }

                                            }
                                        }
                                    }
                                    break;
                                case e_Flow_Labeling.贴标NG放至NG输送上:
                                    {
                                        var NGTempPlate = e_platePro.双平台无;
                                        var ngPros = GlobalVar.Label_pros.Where(a => a.Result_Label == e_Result.贴膜NG.ToString()).ToList();
                                        if ((ngPros == null || ngPros.Count == 0) && !CMachine.Instance.IsTestModel)
                                        {
                                            e_LabelingFlow = e_Flow_Labeling.放行治具;
                                            break;
                                        }
                                        else
                                        {
                                            if (ngPros.Count == 1 && !CMachine.Instance.IsTestModel)
                                            {
                                                if (ngPros[0].ProNo == 1)
                                                    NGTempPlate = e_platePro.平台1;
                                                else
                                                    NGTempPlate = e_platePro.平台2;
                                            }
                                            else
                                            {
                                                NGTempPlate = e_platePro.双平台有;
                                            }
                                        }
                                        var nres = MutilStep_NGPut(NGTempPlate);
                                        if (nres != 1)
                                        {
                                            MachineState(e_MachineStatus.异常急停, $"{NGTempPlate.ToString()}{e_LabelingFlow.ToString()}:NG放工装位");
                                            continue;
                                        }
                                        e_LabelingFlow = e_Flow_Labeling.放行治具;
                                    }
                                    break;
                                case e_Flow_Labeling.放行治具:
                                    {
                                       
                                        if (!GlobalVar.IsOldTest || CMachine.Instance.IsTestModel)
                                            GlobalVar.LabelFinshed = true;  ///发送贴标完成信号
                                        if (GlobalVar.IsEndWork)
                                        {
                                            if (e_ConveryFront == e_Flow_ConveryUp.等待入料治具到位 && e_ConveryLaser == e_Flow_ConveryUp.等待一段治具到位 && !Input_CardEx2[(int)e_input_extCard2.上输送治具检测2])
                                            {
                                                e_LabelingFlow = e_Flow_Labeling.等待开始检测产品信号;
                                                displalyInfo.displayInfoMain("结束作业中+一段已无产品  贴膜流程不再去取膜   等待清料开始 ");
                                                break;
                                            }
                                        }
                                        if (curPlate != e_platePro.双平台无 && !GlobalVar.userConfig.isLabelFinishOK)
                                        {
                                            var nres = Step_Labeling(e_Step_Label.移至取标位上方, e_platePro.双平台有);
                                            if (nres != 1)
                                            {
                                                MachineState(e_MachineStatus.异常急停, $"{e_platePro.双平台有.ToString()}{e_LabelingFlow.ToString()}:移至取标位上方");
                                                continue;
                                            }
                                            e_LabelingFlow = e_Flow_Labeling.取标签;
                                        }
                                        else
                                        {
                                            e_LabelingFlow = e_Flow_Labeling.等待开始检测产品信号;
                                        }
                                    }
                                    break;
                            }
                            if (logFlow != e_LabelingFlow.ToString())
                            {
                                logFlow = e_LabelingFlow.ToString();
                                displalyInfo.displayInfoMain($"贴标流程:{curPlate.ToString()}:" + logFlow);
                            }
                        }
                        else
                            curPlate = e_platePro.双平台有;
                    }
                    else
                    {
                        curPlate = e_platePro.双平台有;
                    }
                }
            }
            catch (Exception ex)
            {
                displalyInfo.displayInfoMain("Task_Labeling" + ex.Message + ex.StackTrace);
            }
        }

    }
}
